/*
 * ResultDialog.cs - Wordtrainer
 * 
 * Copyright (C) 1998-2007 Markus Kilås
 *               
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * Authors:
 *   Markus Kilås <markus@markuspage.com>
 * 
 */

using System;
using System.Collections;
using Gtk;
using Mono.Unix;

namespace WtSharp
{
	
	public delegate void SpecialChangedEventHandler(object source);
	
	public class SpecialCharacters
	{
		private string m_sSpecial1 = "\u00fc";
		private string m_sSpecial2 = "\u00dc";
		private string m_sSpecial3 = "\u00df";
		private string m_sSpecial4 = "\u00f8";
		//private IList m_listeners = new ArrayList();
		public event SpecialChangedEventHandler ChangedEvent;
		
		public SpecialCharacters()
		{
		}
		
		
		
		public string Char1
		{
			set
			{
				m_sSpecial1 = value;
				if(ChangedEvent != null) ChangedEvent(this);
			}
			get
			{
				return m_sSpecial1;
			}
		}
		
		public string Char2
		{
			set
			{
				m_sSpecial2 = value;
				if(ChangedEvent != null) ChangedEvent(this);
			}
			get
			{
				return m_sSpecial2;
			}
		}
		
		public string Char3
		{
			set
			{
				m_sSpecial3 = value;
				if(ChangedEvent != null) ChangedEvent(this);
			}
			get
			{
				return m_sSpecial3;
			}
		}
		
		public string Char4
		{
			set
			{
				m_sSpecial4 = value;
				if(ChangedEvent != null) ChangedEvent(this);
			}
			get
			{
				return m_sSpecial4;
			}
		}
		
		public string Label1
		{
			get
			{
				return "F5: " + m_sSpecial1;
			}
		}
			
		public string Label2
		{
			get
			{
				return "F6: " + m_sSpecial2;
			}
		}
			
		public string Label3
		{
			get
			{
				return "F7: " + m_sSpecial3;
			}
		}
			
		public string Label4
		{
			get
			{
				return "F8: " + m_sSpecial4;
			}
		}
		
		public void SpecialKeyPressed(object o, Gtk.KeyPressEventArgs args)
		{	
			string special;
			if(args.Event.Key == Gdk.Key.F5)
				special = m_sSpecial1;
			else if(args.Event.Key == Gdk.Key.F6)
				special = m_sSpecial2;
			else if(args.Event.Key == Gdk.Key.F7)
				special = m_sSpecial3;
			else if(args.Event.Key == Gdk.Key.F8)
				special = m_sSpecial4;
			else
				return;
			
			Gtk.Entry entry;
			
			if(o is Gtk.ComboBoxEntry)
				entry = ((Gtk.ComboBoxEntry)o).Entry;
			else
				entry = (Gtk.Entry)o;
			
			int pos = entry.Position;
			entry.InsertText(special, ref pos);
			entry.Position+=special.Length;
		}
		
		public void MessageBox1()
		{
			MessageDialog md = new MessageDialog (null, 
	                                      DialogFlags.DestroyWithParent,
				                          MessageType.Info, 
	                                      ButtonsType.Ok, Catalog.GetString("Press F5 when you want to write the special character."));
			md.Run();
			md.Destroy();
		}
		
		public void MessageBox2()
		{
			MessageDialog md = new MessageDialog (null, 
	                                      DialogFlags.DestroyWithParent,
				                          MessageType.Info, 
	                                      ButtonsType.Ok, Catalog.GetString("Press F6 when you want to write the special character."));
			md.Run();
			md.Destroy();
		}
		
		public void MessageBox3()
		{
			MessageDialog md = new MessageDialog (null, 
	                                      DialogFlags.DestroyWithParent,
				                          MessageType.Info, 
	                                      ButtonsType.Ok, Catalog.GetString("Press F7 when you want to write the special character."));
			md.Run();
			md.Destroy();
		}
		
		public void MessageBox4()
		{
			MessageDialog md = new MessageDialog (null, 
	                                      DialogFlags.DestroyWithParent,
				                          MessageType.Info, 
	                                      ButtonsType.Ok, Catalog.GetString("Press F8 when you want to write the special character."));
			md.Run();
			md.Destroy();
		}
		
	}
}
